package com.gitee.swsk33.mapstructdemo.structmapper;

import com.gitee.swsk33.mapstructdemo.dataobject.FigureDO;
import com.gitee.swsk33.mapstructdemo.dto.FigureDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * 用于角色对象转换器
 */
@Mapper(uses = {SpecialWeaponMapper.class, WeaponMapper.class, StoryMapper.class})
public interface FigureMapper {

	FigureMapper INSTANCE = Mappers.getMapper(FigureMapper.class);

	/**
	 * 角色数据对象转换成DTO
	 * 对于guild字段，使用表达式调用GuildMapper的customDOToDTO进行转换
	 */
	@Mapping(target = "guild", expression = "java(GuildMapper.INSTANCE.customDOToDTO(figureDO.getGuild()))")
	FigureDTO toFigureDTO(FigureDO figureDO);

	/**
	 * 角色DTO转数据层
	 * 对于guild字段，使用表达式调用GuildMapper的toGuildDO进行转换
	 */
	@Mapping(target = "guildId", source = "guild.id")
	@Mapping(target = "guild", expression = "java(GuildMapper.INSTANCE.toGuildDO(figureDTO.getGuild()))")
	FigureDO toFigureDO(FigureDTO figureDTO);

}